using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Husb.WinForm.Controls
{
    public class DataGridViewEnumColumn : DataGridViewColumn
    {
        public DataGridViewEnumColumn()
            : base(new DataGridViewEnumCell())
        { }

        public string EnumTypeFullName
        {
            get
            {
                if (this.CellTemplate == null)
                {
                    throw new InvalidOperationException("DataGridViewColumn_CellTemplateRequired");
                }

                return ((DataGridViewEnumCell)this.CellTemplate).EnumTypeFullName;
            }
            set 
            {
                if (this.EnumTypeFullName != value)
                {
                    ((DataGridViewEnumCell)this.CellTemplate).EnumTypeFullName = value;
                }
                if (base.DataGridView != null)
                {
                    DataGridViewRowCollection rows = base.DataGridView.Rows;
                    int count = rows.Count;
                    for (int i = 0; i < count; i++)
                    {
                        DataGridViewEnumCell cell = rows.SharedRow(i).Cells[base.Index] as DataGridViewEnumCell;
                        if (cell != null)
                        {
                            cell.EnumTypeFullName = value;
                        }
                    }
                    base.DataGridView.InvalidateColumn(base.Index);
                }
            }
        }
        public override DataGridViewCellStyle DefaultCellStyle
        {
            get
            {
                return base.DefaultCellStyle;
            }
            set
            {
                base.DefaultCellStyle = value;
            }
        }

        protected override void OnDataGridViewChanged()
        {
            base.OnDataGridViewChanged();
        }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                //if (value != null && !value.GetType().IsAssignableFrom(typeof(CalendarCell)))
                if ((value == null) || !(value is DataGridViewEnumCell))
                {
                    throw new ArgumentException("Invalid cell type, StatusColumns can only contain StatusCells");

                    //throw new InvalidCastException("Must be a DataGridViewEnumCell");
                }
                base.CellTemplate = value;
            }
        }
    }


}
